import sys
import math
from typing import List


def func(n: int, k: int, ducks: List) -> List:
    result = []

    for i in range(0, len(ducks)):
        left = i - k if i - k > 0 else 0
        right = i + k if i + k < len(ducks)-1 else len(ducks)-1
        temp = result[left:i] + ducks[i+1:right+1]
        color = math.floor((max(temp) + min(temp))/2)
        result.append(color)
    return [str(x) for x in result]


if __name__ == '__main__':
    t = int(sys.stdin.readline().strip())
    n_list, k_list, ducks_list = [], [], []

    for _ in range(t):
        line_1 = sys.stdin.readline().strip()
        line_1 = list(map(int, line_1.split(' ')))
        n_list.append(line_1[0])
        k_list.append(line_1[1])

        line_2 = sys.stdin.readline().strip()
        ducks_list.append(list(map(int, line_2.split(' '))))
    for m in range(t):
        colors = func(n_list[m], k_list[m], ducks_list[m])
        print(' '.join(colors))
